import 'package:XinXiZiXun/common/entitys/entitys.dart';
import 'package:XinXiZiXun/common/utils/utils.dart';
import 'package:XinXiZiXun/common/values/values.dart';

/// 全局配置
class Global {
  ///用户配置
  static UserResult profile = UserResult(
    sessionToken: null,
    phone: null,
    avatarUrl: null,
  );

  //持久化 用户信息
  static Future<bool> saveProfile(UserResult userResult) {
    profile = userResult;
    return StorageUtil()
        .setJsonString(Service.STORAGE_USER_PROFILE_KEY, userResult.toJson());
  }

  //获取
  static readProfile() async {
    dynamic result =
        await StorageUtil().getJson(Service.STORAGE_USER_PROFILE_KEY);
    profile = UserResult.fromMap(result);
  }
}
